<?php
if(isset($_POST["type"])){
    $type = $_POST["type"];
    $upload_image = $_POST["base64_code"];
    $base64_image_content ="data:image/jpeg;base64,".$upload_image;
    // echo $upload_image;

    if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
        $type = $result[2];
        $destination_folder = "uploadimg/".date("Y-m-d");
        if(!file_exists($destination_folder))
        {
            mkdir($destination_folder);
        }
        $new_file = $destination_folder."/".uniqid().".".$type;
        if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))) {
            // echo '{"url":"'.$new_file.'"}';
            echo '{"retcode":0,"result":{"w":800,"retcode":0,"flag":1,"h":600,"url":"'.$new_file.'"}}';
        }
    }
}


